﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EKETEAM.FrameWork;
using EKETEAM.Data;

namespace EKECMS.Controls
{
    public partial class mComment : System.Web.UI.UserControl
    {
        public string id = eParameters.QueryString("id");
        protected void Page_Load(object sender, EventArgs e)
        {
            string Type = Pub.getType();
            if (Request.Form["act"] != null)
            {
                #region 安全性检查
                if (Request.UrlReferrer == null) Response.End();
                if (Request.Url.Host.ToLower() != Request.UrlReferrer.Host.ToLower() || Request.Url.Port != Request.UrlReferrer.Port) Response.End();
                #endregion
                #region 提交评论
                if (Session["Plugins_RndCode"] == null)
                {
                    Response.Write("<script>alert('验证码超时！');history.back();</script>");
                    Response.End();
                }
                if (Session["Plugins_RndCode"].ToString() != Request.Form["yzm"].ToString())
                {
                    Response.Write("<script>alert('验证码不正确！');history.back();</script>");
                    Response.End();
                }



                eTable tb = new eTable("eWeb_Comments");
                tb.Fields.Add("SiteID", eBase.getWebSiteID());
                tb.Fields.Add("WebCode", eBase.getWebCode());
                tb.Fields.Add("Type", Type);
                tb.Fields.Add("ParentID", eParameters.Form("id"));
                tb.Fields.Add("nick", eParameters.Form("f1"));
                tb.Fields.Add("email", eParameters.Form("f2"));
                tb.Fields.Add("nr", eParameters.Form("f3"));
                tb.Add();
                //eBase.Writeln(tb.ID);
                //eBase.End();
                Response.Write("<script>alert('您的评论成功提交，感谢您对我们的支持!评论内容需要经过审核才能显示，请耐心等待。');document.location='" + Request.ServerVariables["HTTP_REFERER"].ToString() + "';</script>");
                Response.End();
                //Response.Redirect(Request.ServerVariables["HTTP_REFERER"].ToString(), true);
                #endregion
            }
            eList elist = new eList("eWeb_Comments");
            elist.Where.Add("delTag=0 and show=1");
            elist.Where.Add("Type='" + Type + "'");
            elist.Where.Add("ParentID='" + id + "'");
            elist.OrderBy.Add("addTime");
            elist.Bind(RepList, ePager1);
            if (elist.RecordsCount == 0)
            {
                ePager1.Visible = false;
                LitNoMsg.Text = "<div style=\"padding:50px;\">暂时还没有评论！</div>";
            }
        }
    }
}